<template>
	<view class="scanLogin-page">
		<image src="@/static/icon/pc.png" class="icon" />
		<view class="title">{{ username }}</view>
		<view class="desc">将登录XBoot网页版后台管理系统</view>
		<tui-button :loading="loading" bold width="200px" height="42px" @click="confirm()" class="button">确认登录</tui-button>
		<text @click="cancel()" class="cancel">取消登录</text>
	</view>
</template>

<script>
import { scanLogin } from '@/api/auth.js';
export default {
	data() {
		return {
			checkToken: '',
			loading: false,
			username: ''
		};
	},
	onLoad(options) {
		if (!options.checkToken) {
			this.msg('无效的checkToken');
			uni.navigateBack();
		}
		this.checkToken = options.checkToken;
		this.username = this.getUserInfo().username;
	},
	methods: {
		confirm() {
			this.loading = true;
			scanLogin({
				checkToken: this.checkToken,
				accessToken: this.getToken()
			}).then(res => {
				this.loading = false;
				if (res.result == '2') {
					this.msg('登录成功');
					uni.navigateBack();
				}
			});
		},
		cancel() {
			scanLogin({
				checkToken: this.checkToken,
				cancel: true
			});
			uni.navigateBack();
		}
	}
};
</script>

<style lang="scss" scoped>
@import './scanLogin.scss';
</style>
